from queue import Queue
from typing import List

from config import password
from enumerate.unzip_enum import OtherTool
from factory.CommandExecutorFactory import ExecutorProvider
from factory.JudgementCrpto import JudgementCrypt
from factory.JudgementPath import JudgementPath
from factory.JudgementSoftware import JudgementSoftware


class StartDeCompress:
    def __init__(self):
        self.queue = Queue()
        self.software = JudgementSoftware().get_decompressor()
        self.path = JudgementPath("FileGather").get_path(self.queue)
        self.crypt = JudgementCrypt("aescrypto").get_crypt_processor(password)
        self.executor_command = ExecutorProvider("default").get_executor()

    def start_decompress(self, path, output_path=None, sword="cybz"):
        self.path.set_path(path)
        self.path.start_collection()
        for files in self.path.get_collection():
            for file, ctype in files:
                if OtherTool.can_extract_directly(str(file)):
                    if output_path is None:
                        output_path = file.parent
                    command = self.run_command(file, output_path, sword)
                    self.executor_command.run_command(command)
                    output_path = None

    def run_command(self, input_path, output_path, sword) -> List[str]:
        return self.software.set_input_path(input_path).set_output_path(output_path) \
            .set_password(sword).build_command()


if __name__ == "__main__":
    s = StartDeCompress()
    s.start_decompress(r"E:\myproject\python\extract-script\log\cs", sword="三次郎")
